using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameWork.Source.Texture;
using FrameWork.Source.FrameWork;
using Microsoft.Xna.Framework.Graphics;

namespace FrameWork.Source.Resource_Manager
{
    class CResourceManager
    {
        private static CResourceManager m_pManager = null;

        private CResourceManager()
        {
            m_pListImage = null;
        }

        public static CResourceManager getInstance()
        {
            if (m_pManager == null)
                m_pManager = new CResourceManager();

            return m_pManager;
        }

        public enum RES_STATE
        {
            RES_STATE_LOGO = 0 ,
            RES_STATE_MENU = 1 ,
            RES_STATE_MAIN = 2
        };

        public enum IMG_LOGO
        {
            IMG_LOGO_SPLASH = 0
        };

        public enum IMG_MENU
        {
            MAINBG = 0 ,
            ABOUT = 1 ,
            OPTION = 2 ,
            CHECKED =  3 
        };

        public enum IMG_MAIN
        {
            MAP_OBJECT = 0,
            PLAYER = 1,
            BOOM = 2,
            FRAGMENT = 3,
            BREAKABLE_OBJECT = 4,
            MAPITEM = 5,
            MOBMUMMY = 6,
            MOBMUMMYRAGE = 7,
            MOBBAT = 8,
            BOSS = 9,
            BOSSRAGE = 10 , 
            ILLUSIONEFF = 11 , 
            TELEPORTEFF = 12 ,
            BG = 13 ,
            BOOMT = 14 ,
            MENU = 15 ,
            DYINGEFF = 16 ,
            LOSEBG = 17
        };

        private static string[] menuResPath = { "MenuRes//MenuBG" ,
                                                "MenuRes//About" ,
                                                "MenuRes//Option" ,
                                                "MenuRes//Check" };

        private static string[] logoResPath = { };

        private static string[] mainResPath = { "MainRes//MapObject" ,
                                                "MainRes//Player" ,
                                                "MainRes//Boom" ,
                                                "MainRes//Fragment" ,
                                                "MainRes//BreakableObj" ,
                                                "MainRes//MapItem" ,
                                                "MainRes//MobMummy" ,
                                                "MainRes//MobMummyRage" ,
                                                "MainRes//MobBat" ,
                                                "MainRes//Boss" ,
                                                "MainRes//BossRage" ,
                                                "MainRes//IllusionEffect" ,
                                                "MainRes//TeleportEffect" ,
                                                "MainRes//BG" ,
                                                "MainRes//BoomT" ,
                                                "MainRes//InGameMenu" ,
                                                "MainRes//DyingEffect",
                                                "MainRes//Lose" };

        public CTexture[] m_pListImage;


        public CTexture getImage(int index)
        {
            if (index >= m_pListImage.Length)
                return null;

            return m_pListImage[index];
        }

        public void loadImage(RES_STATE state , StateManager pCurrState)
        {
            if (m_pListImage != null)
            {
                release();
            }

            switch (state)
            {
                case RES_STATE.RES_STATE_MENU:
                    loadImage(menuResPath, pCurrState);
                    break;
                case RES_STATE.RES_STATE_LOGO:
                    loadImage(logoResPath, pCurrState);
                    break;
                case RES_STATE.RES_STATE_MAIN:
                    loadImage(mainResPath, pCurrState);
                    break;
            }
        }

        public void release()
        {
            int size = m_pListImage.Length;

            for (int i = 0; i < size; ++i)
            {
                m_pListImage[i] = null;
            }
        }

        private void loadImage(string[] statePath , StateManager pCurrState)
        {
            int length = statePath.Length;

            m_pListImage = new CTexture[length];
            for (int i = 0; i < length; ++i)
            {
                m_pListImage[i] = new CTexture();
                m_pListImage[i].loadImage(pCurrState.m_pGame.Content.Load<Texture2D>(statePath[i]), pCurrState.m_pSpriteHandler);
            }
        }
    }
}
